package com.yint.core;

import java.io.IOException;
import java.nio.channels.SelectionKey;

import com.yint.server.state.HandlerState;

public abstract class AbsHandler implements Handler {

	@Override
	public final void handle(final SelectionKey selectedKeys) throws IOException {
		if(selectedKeys==null) {
			return;
		}
		try {
			onHandler(selectedKeys);
		}catch (IOException e) {
			e.printStackTrace();
			close();
			throw e;
		}
	}

	protected abstract void onHandler(SelectionKey selectedKeys) throws IOException;
	
	@Override
	public void close() {
		
	}
	
	@Override
	public void changeState(HandlerState state) {
		
	}
}
